#ifndef __VTEMPLATE_H__
#define __VTEMPLATE_H__
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <string>

namespace vstl
{
	//allocator.
	template<typename T>
	class allocator
	{	
	public:
		typedef size_t size_type;
		typedef ptrdiff_t difference_type;
		typedef T  *pointer;
		typedef const T  *const_pointer;
		typedef T & reference;
		typedef const T & const_reference;
		typedef T value_type;
	public:
		inline allocator()
		{	
		}
		inline allocator(const allocator<T>& rhs )
		{
		}
		template<typename _Other>
		inline allocator(const allocator<_Other>& rhs)
		{
		}
		template<typename _Other>
		inline allocator<T>& operator=(const allocator<_Other>& rhs)
		{
			return (*this);
		}
		inline pointer allocate(size_type _Count, const void *)
		{
			return allocate(_Count);
		}
		inline pointer allocate(size_type _Count)
		{
			return (pointer)VMalloc(_Count * sizeof(T) );
		}
		inline void deallocate(pointer _Ptr, size_type)
		{
			VFree(_Ptr);
		}
		inline void construct(pointer _Ptr, const T& _Val)
		{
			new ((void *)_Ptr) T(_Val);
		}
		inline void destroy(pointer _Ptr)
		{	
			(_Ptr)->~T();
		}
		inline size_t max_size() const
		{
			size_t _Count = (size_t)(-1) / sizeof (T);
			return (0 < _Count ? _Count : 1);
		}

		template<typename _Other>
		struct rebind
		{	// convert an allocator<T> to an allocator <_Other>
			typedef allocator<_Other> other;
		};

		inline pointer address(reference _Val) const
		{
			return (&_Val);
		}
		inline const_pointer address(const_reference _Val) const
		{	
			return (&_Val);
		}
		bool operator==(const allocator<T>&) {return true;}
		bool operator!=(const allocator<T>&) {return false;}
	};
	template<class T>
	class vector :public std::vector<T, allocator<T> >
	{
	};
	template<class T>
	class list : public std::list<T, allocator<T> >
	{
	};
	template<class T>
	class deque : public std::deque<T, allocator<T> >
	{

	};

	template<class K, class V, class C = std::less<K> >
	class map : public std::map<K,V,C,allocator<std::pair<const K, V> > >
	{
	};

	template<class Container, class T>
	inline void push_back_unique(Container& c, const T& v)
	{
		if (std::find(c.begin(), c.end(), v) == c.end())
		{
			c.push_back(v);
		}
	}
}

#endif 
